package com.coldfusiondocs.model.presentation
{
    import com.coldfusiondocs.event.ItemClickEvent;
    import com.coldfusiondocs.event.TypeChangeEvent;
    import com.coldfusiondocs.model.ApplicationModel;
    
    import flash.events.EventDispatcher;
    import flash.events.IEventDispatcher;
    
    import mx.collections.ArrayCollection;
    
    public class MainPresentationModel extends EventDispatcher
    {
        
        // PROPERTIES
        
        [Dispatcher]public var dispatcher : IEventDispatcher;
        
		[Inject(source="appModel")]
		public var appModel:ApplicationModel;
		
		[Inject(source="appModel.all_adobe_cfml_categories", bind="true")]
		[Bindable]public var all_adobe_cfml_categories:ArrayCollection;
		
		[Inject(source="appModel.all_adobe_cfml_tags", bind="true")]
		[Bindable]public var all_adobe_cfml_tags:ArrayCollection;			
		
		[Inject(source="appModel.all_railo_cfml_tags", bind="true")]	
		[Bindable]public var all_railo_cfml_tags:ArrayCollection ;
		
		[Inject(source="appModel.currentState", bind="true")]
		[Bindable]public var currentState : String;	
		
		[Inject(source="appModel.isProcessing", bind="true")]
		[Bindable]public var isProcessing : Boolean = false;				
		
		[Bindable] public var cfml_title:String = "";
		[Bindable] public var railo_title:String = "";
		
		[Bindable] public var selectedItem:Object = null ;
		[Bindable] public var railoSelectedItem:Object = null;
		
		public function changeTitle(num:int):void
        {
        	this.cfml_title = "listing " + num + " items...";
        }	
        
		public function changeRailoTitle(num:int):void
        {
        	this.railo_title = "listing " + num + " items...";
        } 
        
		public function setSelectedItem(value:Object):void
		{
			this.selectedItem = value;
			if(!this.isProcessing)
			{
				itemClicked();
			}
		}	
		
		public function setRailoSelectedItem(value:Object):void
		{
			this.railoSelectedItem = value;
			if(!this.isProcessing)
			{
				railoItemClicked();
			}			
		}			               		
		
		public function itemClicked():void
		{
			if(this.selectedItem != null) {
				dispatcher.dispatchEvent(new ItemClickEvent(ItemClickEvent.ITEM_CLICK_ADOBE , this.selectedItem.objectName.toString()) );
			} else {
				// if nothing selected, just hide the right content
				dispatcher.dispatchEvent(new TypeChangeEvent(TypeChangeEvent.TYPE_CHANGE));
			}
		}	
		
		public function railoItemClicked():void
		{
			if(this.railoSelectedItem != null) {
				dispatcher.dispatchEvent(new ItemClickEvent(ItemClickEvent.ITEM_CLICK_RAILO , this.railoSelectedItem.objectName.toString()) );
			} else {
				// if nothing selected, just hide the right content
				dispatcher.dispatchEvent(new TypeChangeEvent(TypeChangeEvent.TYPE_CHANGE));
			}
		}			
		
    }
}